<?php

class Default_ContatoController extends SON_Controller_Action
{
    public function indexAction()
    {
    	$form = new SON_Forms_Contato();
    	 
    	$this->view->form = $form;
    	
        if ($this->_request->isPost()) {
        	$data = $this->_request->getPost();
        	
        	if($form->isValid($data)) {
        		
        		$view = new Zend_View();
        		$view->setScriptPath(APPLICATION_PATH . DIRECTORY_SEPARATOR . 'mailers');
        		
        		$mail = new Zend_Mail('utf-8');
        		$mail->setBodyHtml($view->partial('contato.phtml', array('data' => $data)), 'UTF-8', Zend_Mime::ENCODING_8BIT);
        		$mail->setFrom('contato@votei.net', 'Contato - Votei.Net');
        		$mail->addTo('contato@votei.net', 'Contato - Votei.Net');
        		$mail->setSubject('Novo contato pelo site', 'UTF-8', Zend_Mime::ENCODING_8BIT);
        		$mail->send();
        		
        		$this->_helper->FlashMessenger(
    				array('success' => 'Mensagem enviada com sucesso')
    			);
    
    			$this->_redirect('contato');
        		
        	} else {
        		$this->view->error = $form->getMessages();
        	}
        }
    }
}

